--
-- Author:      feilong
-- DateTime:    2019-10-23 17:19:33
-- Description: 管理服务, 节点间消息的处理

require("skynet.manager")
local skynet = require("skynet")
local NodeMessage = import("NodeMessage")
local MessageDispatch = import("MessageDispatch")
local MessageHandler = import("manager.MessageHandler")
local ClusterManager = import("ClusterManager")
-- local ServerManager = import("ServerManager")
local ServerInfo = import("ServerInfo")


--此服务唯一全局变量
global = {}
--禁止出现别的全局变量
disable_global()

local function init()
	local node_message = NodeMessage.new()
	local message_dispatch = MessageDispatch.new()	
	local message_handler = MessageHandler.new(message_dispatch)
	local cluster_manager = ClusterManager.new(message_dispatch)
	-- local server_manager = ServerManager.new()
	local server_info = ServerInfo.new() --节点相关信息
	-- local user_manager = UserManager.new()

	global.node_message = node_message
	global.message_dispatch = message_dispatch
	global.message_handler = message_handler
	global.cluster_manager = cluster_manager
	global.server_info = server_info
	-- global.server_manager = server_manager
	-- global.user_manager = user_manager

	--开启集群节点
	global.cluster_manager:open(server_info)
	--lua消息的派发
	skynet.dispatch("lua", message_dispatch:dispatch())	

end
---------------------------------------------------------
-- skynet
---------------------------------------------------------



skynet.start(function()	
	skynet.register('.manager')
	init()
end)



